package com.seckill.product.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import com.seckill.product.config.OssUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.seckill.product.entity.ShopEntity;
import com.seckill.product.service.ShopService;
import com.bwie.common.utils.PageUtils;
import com.bwie.common.utils.R;
import org.springframework.web.multipart.MultipartFile;


/**
 * 
 *
 * @author zhuxz
 * @email sunlightcs@gmail.com
 * @date 2022-06-19 09:38:15
 */
@RestController
@RequestMapping("product/shop")
public class ShopController {
    @Autowired
    private ShopService shopService;

    @Autowired
    private OssUtils ossUtils;

    /**
     * 列表
     */
    @RequestMapping("/list")

    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = shopService.queryPage(params);

        return R.ok().put("page", page);
    }

    //图片上传
    @RequestMapping("/upload")
    public R upload(@RequestParam MultipartFile file) {
        return ossUtils.uploadFile(file);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{sid}")

    public R info(@PathVariable("sid") Integer sid){
		ShopEntity shop = shopService.getById(sid);

        return R.ok().put("shop", shop);
    }

    /**
     * 商品添加
     */
    @RequestMapping("/save")
    public R save(@RequestBody ShopEntity shop){
		shopService.save(shop);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")

    public R update(@RequestBody ShopEntity shop){
		shopService.updateById(shop);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")

    public R delete(@RequestBody Integer[] sids){
		shopService.removeByIds(Arrays.asList(sids));

        return R.ok();
    }

}
